package com.mxx.common.netty.http.resolvers;

import com.fasterxml.jackson.databind.JavaType;
import com.mxx.common.conv.JacksonConverter;
import com.mxx.common.netty.http.NettyMethod;
import com.mxx.common.netty.http.NettyMethodParameter;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: Mr. Zeng
 * @Date: 2020/8/4 15:31
 * @Description: 暂无描述
 */
public abstract class AbstractNettyResolvers implements NettyResolvers {
    protected Map<Integer, JavaType> paramType;
    protected JacksonConverter jacksonConverter;

    public AbstractNettyResolvers(JacksonConverter jacksonConverter) {
        this.paramType = new HashMap<>();
        this.jacksonConverter = jacksonConverter;
    }

    public JavaType getJavaType(NettyMethod nettyMethod, NettyMethodParameter methodParameter) {
        return this.paramType.get(getHashCode(nettyMethod, methodParameter));
    }

    public void flashParamType(NettyMethod nettyMethod, NettyMethodParameter methodParameter) {
        JavaType javaType = jacksonConverter.getParameterType(methodParameter.getParameter());
        paramType.put(getHashCode(nettyMethod, methodParameter), javaType);
    }
}
